package com.yeyks.consumer.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yeyks.consumer.dal.dao.UserLoginHistoryMapper;
import com.yeyks.consumer.dal.domain.UserLoginHistory;
import com.yeyks.consumer.service.UserLoginHistoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;


/**
 * <p>
 * 用户登录日志表 服务实现类
 * </p>
 *
 * @author yun
 * @since 2019-11-28
 */
@Service
@Slf4j
public class UserLoginHistoryServiceImpl extends ServiceImpl<UserLoginHistoryMapper, UserLoginHistory> implements UserLoginHistoryService {

    @Override
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.NOT_SUPPORTED)
    public boolean saveByIndependentTransaction(UserLoginHistory demo) {
        try {
            return save(demo);
        } catch (Exception e) {
            log.error("存储用户登录信息失败");
            e.printStackTrace();
        }
        return false;
    }

    /**
     * 查询活跃用户
     *
     * @return
     */
    @Override
    public int getActiveCount() {
        return baseMapper.selectActiveCount();
    }

    /**
     * 查询某段时间内登陆的用户， 单位（天）
     * @param startDate 开始时间
     * @param endDate 结束时间
     * @return
     */
    @Override
    public List<UserLoginHistory> queryFirstLoginByDay(Date startDate, Date endDate) {

        return this.baseMapper.selectFirstLoginByDay(startDate, endDate);
    }

}
